#实现子路由
#1导入APIRouter---->app
from fastapi import APIRouter
#如何传入json
#2.1.导入BaseModel
from pydantic import BaseModel

#2.2. 设置一个类
class User(BaseModel):
    id:int
    name:str
    msg:str|None = None
#2实例化APIRouter
api_user = APIRouter()

#3接口设计
@api_user.post('/add')
def addUser(user:User):
    user.msg = '增加user'
    return user

@api_user.get('/get') #/get?id = 1
def get_user(id:int):

    dict1 = {'id':id,'name':'小明'}

    dict1['test'] = 'ajshd'

    return dict1

@api_user.post('/update')
def modUser(user:User):
    return '改'

#4.将子路由加载到主路由mian的app中


